Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
How do we know what are "Local Defaults" while using Property Injection?

I was reading the book Dependency Injection in .NET, by Mark Seemann, where I stumbled upon the topic of Property Injection.

As the book described for using the Property Injection the condition was:

1) When the use of Dependency Injection is optional
2) When we have a good Local Default

As I searched through the internet about "Local Default", I didn't get any significant definitions for this concept.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In both editions of the book, a definition and description of Local Default can be found in section 4.2.2. The second edition states:

DEFINITION: A Local Default is a default implementation of a Dependency that originates in the same module or layer.

Local Default

When you're developing a class that has a Dependency, you probably have a particular implementation of that Dependency in mind. If you're writing a domain service that accesses a Repository, you're most likely planning to develop an implementation of a Repository that uses a relational database.

It would be tempting to make that implementation the default used by the class under development. But when such a prospective default is implemented in a different assembly, using it as a default means creating a hard reference to that other assembly, effectively violating many of the benefits of loose coupling described in chapter 1. Such implementation is the opposite of a Local Default—it's a Foreign Default. A class that has a hard reference to a Foreign Default is applying the Control Freak anti-pattern. We'll discuss Control Freak in chapter 5.

Conversely, if the intended default implementation is defined in the same library as the consuming class, you won't have that problem. This is unlikely to be the case with Repositories, but such Local Defaults often arise as implementations of the Strategy pattern.

NOTE: The text for Local Default in the first edition is slightly different, but not that different. I used the text of the second edition, because I don't have the text of the first edition in an easily copy/pasteable form at my disposal.

TIP: Since you are at the beginning of the book, my advise would be to switch to the second edition, as it is the most recent version, and an overall improvement of the book. This blog post describes the improvements Mark and I made in that edition.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!